<?php
class UpdateController extends Zend_Controller_Action
{	
    function init()
    {
		$auth = Zend_Auth::getInstance();
		if(!$auth->hasIdentity()){
		$this->_redirect('/index/index');
		}
		$this->initView();		
        $this->view->baseUrl = $this->_request->getBaseUrl();
 		$this->view->title = 'plima';
		$this->view->user = (array)Zend_Auth::getInstance()->getIdentity();
		$this->db=Zend_Registry::get('dbAdapter');
		if(!empty($this->view->user)){			
			$this->view->role=$this->view->user['role'];			
			$select=$this->db->select();
			$select->from('admin_user','*');			
			$select->join('plm_role','admin_user.role=plm_role.role_name','*');
			$select->where('admin_user.username = ?',$this->view->user['username']);
			$result=$this->db->fetchRow($select);			
			$acl=unserialize($result['role_acl']);
			$this->view->acl=$acl;
		}		
    }
 
   function indexAction() 
    { 	
		$id=$this->_request->getParam('id');
		$config=Zend_Registry::get('config');
		$url=$config->$id->url;		
		$this->view->id=$id;
		$this->view->website='http://'.$url;
		$this->view->title = 'plima管理系统';
		$this->render();		
    } 
 	
	function serverproductAction(){
		Zend_Loader::loadClass('product');
		$id=$this->_request->getParam('id');
		$start=$this->_request->getParam('start')?$this->_request->getParam('start'):"0";
		$limit=$this->_request->getParam('limit')?$this->_request->getParam('limit'):"30";
		$ids=$this->_request->getParam('ids');
		$type=$this->_request->getParam('type');
		$product=new product($id);
		if(empty($ids)){			
			$products=$product->getAll();
			$total=sizeof($products);
			$products=array_slice($products,$start,$limit);
			result($total,$products);			
			exit;
			}
		if($type==0){
			//普通操作方式
			$_arrayIds=explode(",",$ids);
		}
		else{
			$_arrayIds=array();
			$_temp=explode(",",$ids);
			foreach($_temp as $item){
				$_tempArray=explode("-",$item);
				if(count($_tempArray)>1){
					for($i=$_tempArray[0];$i<=$_tempArray[1];$i++){
						$_arrayIds[]=$i;
						}
				}
				else{
					$_arrayIds[]=$_tempArray[0];
					}
				}
			}
		//print_r($_arrayIds);exit;
		
		$products=$product->getSomeProduct($_arrayIds,$start,$limit);
		//print_r($products);
		result($products['total'],$products["data"]);
		
		//mivec modify start
		Zend_Loader::loadClass('Mivec_Element_Array');
		Zend_Loader::loadClass('Mivec_Element_String');
		
		Zend_Loader::loadClass('Clone_Product');
		Zend_Loader::loadClass('Clone_Image');
		exit;
		}
	
	function __call($method,$args){
		if ('Action' == substr($method, -6)) 
    	{            
    		// If the action method was not found, forward to the index action            
    		return $this->_forward('index');        
    	}        
    	// all other methods throw an exception        
    	throw new Exception('Invalid method "' . $method . '" called');    
		}
}
?>